package com.azdebugit.xiangmu.need.test.image.test;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import javax.imageio.ImageIO;

public class CalPit {
    public static void main(String[] args) throws FileNotFoundException, IOException {
        CalPit calPit = new CalPit();
      /*  File picture = new File("D:\\BaiduNetdiskWorkspace\\me\\h1.png");
        BufferedImage sourceImg = ImageIO.read(new FileInputStream(picture));
        System.out.println(String.format("%.1f", picture.length() / 1024.0));
        System.out.println(sourceImg.getWidth());
        System.out.println(sourceImg.getHeight());*/
//        String path = CalPit.getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
//        String path = request.getContextPath();
        String path = Thread.currentThread().getContextClassLoader().getResource("").getPath();
        System.out.println("----######----"+path);
        System.out.println("----######----"+calPit.sysPath());
    }

    public  String sysPath() {
        String path = this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
        if (path.toLowerCase().indexOf("bizapp-interact-apiserver") != -1) {
            try {
                //截取"bizapp-interact-apiserver第一次出现前的字符串"
                String StrPath = path.substring(0, path.toLowerCase().indexOf("bizapp-interact-apiserver"));
                //获取“bizapp-interact-apiserver”的上一层文件夹
                path = StrPath.substring(0, StrPath.lastIndexOf("/") + 1);
            } catch (Exception e) {
                return "出错了:" + e.toString();
            }
        }
        return path;
    }
}